<?php
    $this->layout('base.phtml', [
        'title' => _('My links'),
        'canonical' => url_full('links'),
        'current_tab' => 'links',
        'current_page' => 'links',
        'back_options' => [
            'reset' => true,
        ],
        'search_options' => [
            'enabled' => true,
            'query' => $this->safe('query'),
        ],
    ]);
?>

<div class="section">
    <div class="section__title">
        <h1><?= _('My links') ?></h1>
    </div>

    <p class="section__intro">
        <?= _('Organize your links in your thematic collections.') ?>
    </p>

    <section class="group">
        <div class="cards">
            <div class="card">
                <button
                    class="card__button"
                    data-controller="modal-opener"
                    data-action="modal-opener#fetch"
                    data-modal-opener-href-value="<?= url('new collection') ?>"
                    aria-haspopup="dialog"
                    aria-controls="modal"
                >
                    <?= icon('plus') ?><br />
                    <?= _('Create a collection') ?>
                </button>
            </div>

            <?php $collections = $groups_to_collections[null] ?? []; ?>
            <?php foreach ($collections as $collection): ?>
                <?= $this->include('collections/_collection.phtml', [
                    'collection' => $collection,
                    'display_by' => false,
                    'display_number_links' => true,
                    'display_visibility' => $collection->is_public,
                ]) ?>
            <?php endforeach; ?>

            <?php for ($i = 0; $i < (3 - ((count($collections) + 1) % 3)); $i++): ?>
                <div class="card card--shadow no-mobile"></div>
            <?php endfor; ?>
        </div>
    </section>

    <?php foreach ($groups as $group): ?>
        <?php if (isset($groups_to_collections[$group->id])): ?>
            <?= $this->include('groups/_group.phtml', [
                'group' => $group,
                'collections' => $groups_to_collections[$group->id],
                'display_by' => false,
                'display_number_links' => true,
                'display_visibility' => true,
                'from' => url('links'),
            ]) ?>
        <?php endif; ?>
    <?php endforeach; ?>

    <?php if ($shared_collections): ?>
        <section class="group">
            <header class="group__header">
                <div class="group__icon">
                    <?= icon('share') ?>
                </div>

                <h2 class="group__title">
                    <?= _('Shared with me') ?>
                </h2>

                <div class="group__separator"></div>
            </header>

            <div class="cards">
                <?php foreach ($shared_collections as $collection): ?>
                    <?= $this->include('collections/_collection.phtml', [
                        'collection' => $collection,
                        'display_by' => true,
                        'display_number_links' => true,
                        'display_visibility' => $collection->is_public,
                    ]) ?>
                <?php endforeach; ?>

                <?php for ($i = 0; $i < (3 - (count($shared_collections) % 3)); $i++): ?>
                    <div class="card card--shadow no-mobile"></div>
                <?php endfor; ?>
            </div>
        </section>
    <?php endif; ?>

    <img
        class="illustration illustration--centered"
        alt=""
        src="<?= url_static('illustrations/inspiration.svg') ?>"
        height="250"
    />
</div>
